package com.cmbchina.designpattern.adapter;

import com.cmbchina.designpattern.adapter.dto.DestroyRequest;
import com.cmbchina.designpattern.adapter.dto.DestroyResult;
import com.cmbchina.designpattern.application.BigBadWolf;
import com.cmbchina.designpattern.application.Pig;
import com.cmbchina.designpattern.application.house.ThatchedHouse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WolfComingController {

    @DeleteMapping("/firstPigsHouse")
    @ResponseBody
    public DestroyResult destroyFirstPigsHouse(@RequestBody DestroyRequest request) {
        // 小猪建房
        Pig pig = new Pig(request.getPigName());
        ThatchedHouse house = pig.buildThatchedHouse();

        // 大野狼毁房
        BigBadWolf bigBadWolf = new BigBadWolf();
        boolean destroyed = bigBadWolf.blowHouse(house);

        return new DestroyResult(destroyed, house.toString());
    }

}
